tools: fix sysfs error path
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 21 Jan 2010 11:27:11 +0000 (11:27 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 21 Jan 2010 11:27:11 +0000 (11:27 +0000)
Attached patch fixes sysfs error path.
NetBSD also has a /proc/mounts file but no sysfs.
On Linux you can test this with sysfs not mounted.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
tools/python/xen/util/pci.py
tools/python/xen/util/utils.py
tools/python/xen/util/vscsi_util.py

index 35c804495cf8a5a473498f043e9aadc01d6edde0..6aac0b5ba76a2803fa89cf2b88ca620a18028ec5 100644 (file)
@@ -441,6 +441,8 @@ def find_sysfs_mnt():
 
 def get_all_pci_names():
     sysfs_mnt = find_sysfs_mnt()
+    if sysfs_mnt is None:
+        return None
     pci_names = os.popen('ls ' + sysfs_mnt + SYSFS_PCI_DEVS_PATH).read().split()
     return pci_names
 
index 6d0c5ab8cb57514637e9919fa957ed0781f96b0c..6be3e8e202db30baeb687d049951e992db0dc93e 100644 (file)
@@ -68,7 +68,9 @@ def find_sysfs_mount():
                 continue
             if sline[2] == 'sysfs':
                 sysfs_mount_point= sline[1]
-                return sysfs_mount_point
+                break
+        mounts_file.close()
+        return sysfs_mount_point
     except IOError, (errno, strerr):
         raise
 
index 8b26117fca6164feba7ce9daeae17c97b11eea38..15719782fa61e8131604437b15f9da48f9649c17 100644 (file)
@@ -123,6 +123,9 @@ def _vscsi_get_scsidevices_by_sysfs():
     except:
         return devices
 
+    if sysfs_mnt is None:
+        return devices
+
     for dirpath, dirnames, files in os.walk(sysfs_mnt + SYSFS_SCSI_PATH):
         for hctl in dirnames:
             paths = os.path.join(dirpath, hctl)